package main.graph;

import java.io.File;
import java.io.IOException;

import main.entity.Hero;
import main.entity.LeveledHero;
import main.math.Calculator;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class Graph {
	
	public XYSeries getSeriesFromHero(Hero hero, int init, int step, int max){
		XYSeries serie = new XYSeries(hero.getName());
		
		
		for(int i =init; i<=max;i+=step){
			
			LeveledHero levelHero = Calculator.getHeroAt(hero, i);
			
			serie.add(levelHero.getSuperRoundedTotalGold()/*i*/, levelHero.getSuperRoundedDPS());
			
		}
		
		return serie;
	}
	
	public void printGraph(String name, int init, int step, int max,Hero... heroes){
		
		XYSeriesCollection dataset = new XYSeriesCollection();
		
		for (Hero hero : heroes) {
			dataset.addSeries(getSeriesFromHero(hero, init, step, max));
			
		}
		
		// Generate the graph
		JFreeChart chart = ChartFactory.createXYLineChart(name, // Title
				"Total Gold", // x-axis Label
				"Total DPS", // y-axis Label
				dataset, // Dataset
				PlotOrientation.VERTICAL, // Plot Orientation
				true, // Show Legend
				true, // Use tooltips
				false // Configure chart to generate URLs?
				);
		
		
		try {
			ChartUtilities.saveChartAsJPEG(new File(name+".jpg"), chart,
					1500, 500);
		} catch (IOException e) {
			System.err.println("Problem occurred creating chart.");
		}
		
		
	}

}
